class ConfigConteudosController < ApplicationController
  # GET /config_conteudo
  # GET /config_conteudo.xml
  def index
    @config_conteudos = ConfigConteudo.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @config_conteudo }
    end
  end

  # GET /config_conteudo/1
  # GET /config_conteudo/1.xml
  def show
    @config_conteudo = ConfigConteudo.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @config_conteudo }
    end
  end

  # GET /config_conteudo/new
  # GET /config_conteudo/new.xml
  def new
    @config_conteudo = ConfigConteudo.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @config_conteudo }
    end
  end

  # GET /config_conteudo/1/edit
  def edit
    @config_conteudo = ConfigConteudo.find(params[:id])
  end

  # POST /config_conteudo
  # POST /config_conteudo.xml
  def create
    @config_conteudo = ConfigConteudo.new(params[:config_conteudo])

    respond_to do |format|
      if @config_conteudo.save
        flash[:notice] = 'ConfigConteudo was successfully created.'
        format.html { redirect_to(@config_conteudo) }
        format.xml  { render :xml => @config_conteudo, :status => :created, :location => @config_conteudo }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @config_conteudo.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /config_conteudo/1
  # PUT /config_conteudo/1.xml
  def update
    @config_conteudo = ConfigConteudo.find(params[:id])
    @config_conteudo.config_conteudo_categorizacao.clear
    params[:categoria].each do |categoria_id|
      @config_conteudo.config_conteudo_categorizacao << ConfigConteudoCategorizacao.new({
          'categoria_id'=>categoria_id,
          'config_conteudo_id'=>self.id
      })
    end
    respond_to do |format|
      if @config_conteudo.update_attributes(params[:config_conteudo])
        flash[:notice] = 'ConfigConteudo was successfully updated.'
        format.html { redirect_to(config_conteudos_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @config_conteudo.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /config_conteudo/1
  # DELETE /config_conteudo/1.xml
  def destroy
    @config_conteudo = ConfigConteudo.find(params[:id])
    @config_conteudo.destroy

    respond_to do |format|
      format.html { redirect_to(config_conteudo_url) }
      format.xml  { head :ok }
    end
  end
end
